package portrait

import org.apache.commons.lang.StringUtils
import org.apache.spark.broadcast.Broadcast
import org.apache.spark.sql.Row

object appTags extends Tags {
  override def makeTags(any: Any*): List[(String, Int)] = {
    val row = any(0).asInstanceOf[Row]
    val dictBro = any(1).asInstanceOf[Broadcast[Map[String,String]]]
    var list = List[(String, Int)]()
    var appName = row.getAs[String]("appname")
    val appId = row.getAs[String]("appid")
    if (StringUtils.isEmpty(appName)) {
      if (StringUtils.isNotEmpty(appId)) {
        appName = dictBro.value.getOrElse(appId, appId)
      } else {
        appName = "moapp"
      }
    }
    list :+= ("APP" + appName, 1)


    val adplatformproviderid = row.getAs[Int]("adplatformproviderid")
    if (adplatformproviderid >= 100000) {
      list :+= ("CN" + adplatformproviderid, 1)
    }
    list
  }
}
